package com.springapp.utils;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class JdbcUtil {
	
	public Map getURL() {
		Properties p = new Properties();
		try {
			 String classpath=System.getProperty("user.dir");
			 String path=classpath+File.separator+"agent";
	         InputStream in = new BufferedInputStream (new FileInputStream(path+File.separator+"jdbc.properties"));
	         p.load(in);
	         System.out.println(path+File.separator+"jdbc.properties");
	             
	        } catch (Exception e) {
	         e.printStackTrace();
	        
	        }
		StringBuilder url =new StringBuilder();
		url.append(p.getProperty("url").trim());
		url.append("?&useUnicode=true&characterEncoding=utf-8");
		String username = p.getProperty("user").trim();
		String pwd = p.getProperty("password").trim();
		String debug=null;
		try {
			if(p.getProperty("debug")!=null&&p.getProperty("debug")!=""){
				debug=p.getProperty("debug").trim();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			
		}
		
		//String driver=p.getProperty("driver");
		Map map = new HashMap();
		map.put("url", url.toString());
		map.put("uname", username);
		map.put("pwd", pwd);
		
		//map.put("driver", driver);
		return map;
	}
	
	
	public static void main(String[] args) {
		JdbcUtil uti= new JdbcUtil();
		uti.getURL();
	}

}
